package com.dailyblue.example.project.bookstore.logistics.listener;

import com.alibaba.fastjson.JSONArray;
import com.dailyblue.example.project.bookstore.commons.bean.Logistics;
import com.dailyblue.example.project.bookstore.logistics.service.LogisticsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "logistics_group", topic = "ORDER3", selectorExpression = "LOGISTICS",messageModel = MessageModel.BROADCASTING)
public class OrderListener implements RocketMQListener<String> {
    @Resource
    private LogisticsService service;

    @Override
    public void onMessage(String s) {
        Logistics logistics = JSONArray.parseObject(s, Logistics.class);
        log.info("logistics:{}", logistics);
        service.saveLogistics(logistics);
    }
}
